package com.yoomiito.app.ui.anyview.goodsinfo.bottom;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yoomiito.app.R;
import com.yoomiito.app.base.App;
import com.yoomiito.app.base.BaseActivity;
import com.yoomiito.app.interf.BaseBottomBar;
import com.yoomiito.app.model.bean.GoodsDetail;
import com.yoomiito.app.ui.order.sureorder.singleGoods.BuyGoodsActivity;
import com.yoomiito.app.utils.AllCode;
import com.yoomiito.app.utils.AllEventID;
import com.yoomiito.app.utils.RouterUtils;
import com.yoomiito.app.utils.SpannableUtils;
import com.yoomiito.app.utils.TouchUtils;
import com.yoomiito.app.utils.Type;
import com.yoomiito.app.utils.UserInfoConfig;

/**
 * 礼包详情 ---- 底部状态栏
 */
public class GiftBottomBar extends BaseBottomBar {
    private TextView mShareAwardTv;
    private TextView mShareContentTv;
    private LinearLayout mAwardLl;
    private TextView mAwardTv;
    private TextView mShowYouMiTv;
    public GiftBottomBar(Context context, boolean isLogin) {
        super(context, isLogin);
        LayoutInflater.from(context).inflate(R.layout.youpin_bottom_btn, this, true);
        initView();
    }

    private void initView() {
        mAwardLl = findViewById(R.id.award_ll);
        mAwardTv = findViewById(R.id.award);
        mShareAwardTv = findViewById(R.id.show_award);
        mShareContentTv = findViewById(R.id.share_bottom);
        mShowYouMiTv = findViewById(R.id.show_youmi);
        findViewById(R.id.bg_3).setOnClickListener(v -> {
            if (checkClick()){
                TouchUtils.onEvent(AllEventID.GiftShareEvnetId, UserInfoConfig.getRoleId(), UserInfoConfig.getAgent());
                RouterUtils.toShareGoods((BaseActivity) mContext, String.valueOf(mGoodsDetail.getNum_iid()), AllCode.Gift);
            }
        });

        findViewById(R.id.bg_2).setOnClickListener(v -> {
            if (checkClick()){
                TouchUtils.onEvent(AllEventID.GiftBuyEventId, UserInfoConfig.getRoleId(), UserInfoConfig.getAgent());
                BuyGoodsActivity.start(mContext, mGoodsDetail, AllCode.Gift);

//                canBuy(String.valueOf(mGoodsDetail.getNum_iid()))
//                        .subscribe(new ApiSubscriber<BaseRepository>() {
//                            @Override
//                            public void onSuccess(BaseRepository baseModel) {
//                            }
//
//                            @Override
//                            public void onFail(ApiException error) {
//                                YMToast.showText(error.getMsg());
//                            }
//                        });
            }

        });
    }


    @Override
    public void updateInfo(GoodsDetail detail) {
        super.updateInfo(detail);
        mShowYouMiTv.setVisibility(SpannableUtils.isEmptyOr0(String.valueOf(detail.getYo_money()))?GONE:VISIBLE);//优币
        mShowYouMiTv.setText("送" + detail.getYo_money()+"优米");
        if (App.mAppConfig.getIsLogin()){
            int roleId = UserInfoConfig.getRoleId();
            if (roleId > Type.LevelType.VIP_7) {
                boolean IsShow = SpannableUtils.isEmptyOr0(detail.getGet_money());
                mShareAwardTv.setVisibility(IsShow?GONE:View.VISIBLE);//分享佣金
                mAwardLl.setVisibility(IsShow?GONE:View.VISIBLE);//奖励佣金
                mAwardTv.setText("返佣¥"+detail.getGet_money());
                mShareAwardTv.setText("奖励：¥" + detail.getGet_money());
//                mShareContentTv.setText("分享赚钱");
            } else {
//                mShareContentTv.setText("分享");
                mAwardLl.setVisibility(View.GONE);
                mShareAwardTv.setVisibility(GONE);
            }
        }
    }
}
